package com.bytedance.scenedemo.multi_stack;

import com.bytedance.scene.group.GroupScene;
import com.bytedance.scene.ktx.SceneExtensions;
import com.bytedance.scenedemo.ResourceTable;
import com.bytedance.scenedemo.utility.ColorUtil;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.IntentParams;
import ohos.agp.components.*;

/**
 * Created by JiangQi on 8/7/18.
 */
public class MultiStackTabChildScene extends GroupScene {

    Text textPath;
    @Override
    public ComponentContainer onCreateView(LayoutScatter scatter, ComponentContainer container, Intent intent) {
        Component layout=scatter.parse(ResourceTable.Layout_single_task_demo_scene,container,false);
        ScrollView svMain= (ScrollView) layout.findComponentById(ResourceTable.Id_sv_single_task_demo_scene_main);
        Text textHint= (Text) layout.findComponentById(ResourceTable.Id_text_single_task_demo_scene_hint);
        textPath= (Text) layout.findComponentById(ResourceTable.Id_text_single_task_demo_scene_path);
        Button btnGoTo= (Button) layout.findComponentById(ResourceTable.Id_btn_single_task_demo_scene_goto);
        Button btnGoTo1= (Button) layout.findComponentById(ResourceTable.Id_btn_single_task_demo_scene_goto1);
        Button btnGoTo2= (Button) layout.findComponentById(ResourceTable.Id_btn_single_task_demo_scene_goto2);
        btnGoTo.setText("清除显示");
        btnGoTo1.setText("在当前 Tab 的栈中启动空白的 Scene");
        btnGoTo2.setText("在整个页面的栈中启动空白的 Scene");


        int index=0;
        if(getArguments()!=null){
            index= (int) getArguments().getParam("index");
        }
        svMain.setBackground(ColorUtil.getMaterialColor(index));
        textHint.setText(getClassName());


        btnGoTo.setClickedListener(component -> {
            textPath.setText("");
        });
        btnGoTo1.setClickedListener(component -> {
            SceneExtensions.getNavigationScene(this).push(EmptyScene.class);
        });
        btnGoTo2.setClickedListener(component -> {
            SceneExtensions.getNavigationScene(getParentScene()).push(EmptyScene.class);
        });

        return (ComponentContainer) layout;
    }

    @Override
    public void onResume() {
        super.onResume();
        textPath.setText(getStateHistory());
    }

}

